<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/3/14
 * Time: 16:57
 */
namespace app\admin\controller;
use think\Db;
class Form  extends Base {
    public function formmf(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($h_type)&&$h_type != ""){
                $map['status'] = $h_type;
            }
            if(isset($key)&&$key!="")
            {
                $map['name|phone'] = ['like',"%" . $key . "%"];
            }
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_form')->alias('f')
                ->join('up_u_user u','f.uid=u.user_id','LEFT')
                ->where($map)
                ->count();
            $lists = Db::table('up_form')->alias('f')
                ->join('up_u_user u','f.uid=u.user_id','LEFT')
                ->where($map)
                ->page($page,$limit)
                ->field('f.*,u.user_id,user_phone,user_image,user_username')
                ->order('status asc,time desc')
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch();
    }

    /***
     * @return \think\response\Json
     * 删除
     */
    public function delmf(){
        $res = Db::name('form')->where('id',input('id'))->delete ();
        if($res){
            return json(['code'=>200,'msg'=>'删除成功']);
        }else{
            return json(['code'=>100,'msg'=>'删除失败']);
        }
    }
    
    public function updatemf(){
        if(request()->isPost ()){
            extract(input());
            $data = array();
            $data['city'] = $city;
            $data['xiaoqu'] = $xiaoqu;
            $data['house'] = $house;
            $data['money'] = $money;
            $data['phone'] = $phone;
            $data['name'] = $name;
            $data['sex'] = $sex;
            $data['status'] = $status;
            $data['remark'] = $remark;
            $res = Db::table('up_form')->where('id',$id)->update($data);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $info = Db::table('up_form')->where('id', input('id'))->find();
        return $this->fetch('form/updatemf',['info'=>$info]);
    }

    //------------------------------------------------------------------------------------'

    public function formzx(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($h_type)&&$h_type != ""){
                $map['status'] = $h_type;
            }
            if(isset($key)&&$key!="")
            {
                $map['name|phone'] = ['like',"%" . $key . "%"];
            }
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::table('up_form_fit')->alias('f')
                ->join('up_u_user u','f.uid=u.user_id','LEFT')
                ->where($map)
                ->count();
            $lists = Db::table('up_form_fit')->alias('f')
                ->join('up_u_user u','f.uid=u.user_id','LEFT')
                ->where($map)
                ->page($page,$limit)
                ->field('f.*,u.user_id,user_phone,user_image,user_username')
                ->order('status asc,time desc')
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch();
    }

    /***
     * @return \think\response\Json
     * 删除
     */
    public function delzx(){
        $res = Db::name('form_fit')->where('id',input('id'))->delete ();
        if($res){
            return json(['code'=>200,'msg'=>'删除成功']);
        }else{
            return json(['code'=>100,'msg'=>'删除失败']);
        }
    }

    public function updatezx(){
        if(request()->isPost ()){
            extract(input());
            $data = array();
            $data['city'] = $city;
            $data['mianji'] = $mianji;
            $data['shi'] = $shi;
            $data['wei'] = $wei;
            $data['ting'] = $ting;
            $data['yusuan'] = $yusuan;
            $data['phone'] = $phone;
            $data['name'] = $name;
            $data['sex'] = $sex;
            $data['status'] = $status;
            $data['remark'] = $remark;
            $res = Db::table('up_form_fit')->where('id',$id)->update($data);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $info = Db::table('up_form_fit')->where('id', input('id'))->find();
        return $this->fetch('form/updatezx',['info'=>$info]);
    }
}